﻿<!DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>接受人选择器</title>
    <link href="../Scripts/layui/layui/css/layui.css" rel="stylesheet" />
    <link href="../Scripts/easyUI145/themes/default/easyui.css" rel="stylesheet" type="text/css" />

    <script src="../Scripts/jquery-1.7.2.min.js" type="text/javascript"></script>
    <script src="../Scripts/layui/layui/layui.js" type="text/javascript"></script>
    <link href="../Scripts/bootstrap/css/components-rounded.css" rel="stylesheet" />
    <!--<script type="text/javascript" src="../Scripts/bootstrap/js/bootstrap.min.js"></script>-->
    <script type="text/javascript" src="../Scripts/commonYangYH.js"></script>
    <script src="../Scripts/QueryString.js" type="text/javascript"></script>
    <script src="../Scripts/bootstrap/js/jquery.cokie.min.js" type="text/javascript"></script>
    <script type="text/javascript" src="../Scripts/config.js"></script>
    <script src="../Comm/Gener.js" type="text/javascript"></script>
    <script type="text/javascript" src="../Scripts/bootstrap/js/jstree.js"></script>
    <link href="../Scripts/layui/layui/css/layui.css" rel="stylesheet" />
    <link href="../../DataUser/Style/ccbpm.css" rel="Stylesheet" />
    <!--
       杨玉慧.

    1. 初始化的标记是 ?DoType=Accepter_Init&FK_Node=xxxx&ToNode=0&WorkID=xxxxx.  参数: WorkID
       返回的是 节点列表 Nodes, 部门列表 Depts, 人员列表 Emps

    2, 用户选择一个节点，标记是 DoType=Accepter_Save&FK_Node=xxx&WorkID=xxx&ToNode=xxxx&SelectEmps=zhangsan,lisi.
       返回的是: 保存结果.
    -->
    <style type="text/css">
        * {
            list-style: none;
            text-align: left;
        }

        body .table tbody tr td {
            line-height: 18px;
        }

        .portlet-body, .portlet-title {
            background: #f4f9ff !important;
            border-bottom: 0px;
        }

        .customthr tr:nth-child(2n) {
            background: #d4e6fe;
        }

        .customthr tr:nth-child(2n+1) {
            background: #f4f9ff;
        }

        .customthr thead tr {
            background: #d4e6fe !important;
        }

        /*.btn {
            background: #2884fa !important;
            border-radius: 3px !important;
            color: white !important;
            padding: 4px 17px !important;
        }

        #btnCancel {
            background: #50b6ac !important;
            border-radius: 3px !important;
            color: white !important;
            padding: 4px 17px !important;
        }*/
/*
        input[type=text], select {
            border-radius: 15px !important;
            border: #2884fa 1px solid !important;
            margin: 8px 0px !important;
            line-height: 25px;
            padding-left: 6px;
        }*/

        /*#btnSearch {
            height: 30px;
            border: none;
            border-radius: 20px;
            padding: 6px 12px;
            margin-bottom: 0;
            font-size: 14px;
            background: #2884fa !important;
            color: #fff;
        }*/

        #txbSearchVal {
            font-size: 14px;
        }
        /*#poptable {
                display: none;
            }*/
        #test {
        }

        .form_tree {
            background: #f4f9ff;
        }

            .form_tree #orgTxt {
                border-radius: 15px 0px 0px 15px !important;
                margin: 0px !important;
                /*border:#2884fa 1px solid;*/
            }

            .form_tree .input-group-addon {
                border-radius: 0px 15px 15px 0px !important;
                /*broder:#2884fa 1px solid;*/
            }

        #groupTable #dt ul {
            /*background: #f4f9ff;*/
            font-weight: normal;
            background: #d4e6fe;
        }

        #groupTable #dt > li {
            font-weight: bold;
        }

        #searchS {
            overflow: hidden;
        }

            #searchS div {
                height: 40px;
                line-height: 40px;
                text-align: left;
                float: left;
            }
    </style>
    <script type="text/javascript">
        var doType = GetQueryString("DoType");
        var isFrameCross = GetQueryString("isFrameCross");
        if (isFrameCross == null || isFrameCross == undefined || isFrameCross == "" || isFrameCross == "null")
            isFrameCross = 0;
        var isDelayedSend = GetQueryString("IsDelayedSend") || "0";
        var pageFrom = GetQueryString("PageFrom");
        $(function () {
            
            var IsSend = GetQueryString("IsSend");
            if (IsSend == null || IsSend == undefined)
                IsSend = 1;

            if (IsSend == 0) {
                $("#Btn_Save").show();
                $("#Btn_Send").hide();
            } else {
                $("#Btn_Save").hide();
                $("#Btn_Send").show();
            }
            if (isDelayedSend == "1") {
                $("#Btn_Send").hide();
                $("#Div_DelayedSend").show();
                $("#Btn_DelayedSend").show();
            }
            var handler = new HttpHandler("BP.WF.HttpHandler.WF_WorkOpt");
            handler.AddUrlData(); //这里是获得Url的参数.
            var data = handler.DoMethodReturnString("Accepter_Init");

            //对返回值处理，如果是info 仅仅提示信息.
            if (data.indexOf('info@') == 0) {
                data = data.replace('info@@', '');
                data = data.replace('info@', '');
                alert(data);
                Close(true);
                return;
            }

            //如果有错误，直接提示错误.
            if (data.indexOf('err@') == 0) {
                alert(data);
                Close(false);
                return;
            }
            if (data.indexOf('TurnUrl@') == 0) {  //发送成功时转到指定的URL
                var url = data;
                url = url.replace('TurnUrl@', '');
                parent.window.location.href = filterXSS(url);
                return;
            }
            //如果包含url ,则是需要转向不同的url里面去.
            if (data.indexOf('url@') == 0) {

                var url = data.replace('url@', '');

                if (url.indexOf('ToNode=') > 0)
                    SetHref(url + "&IsDelayedSend=" + isDelayedSend + "&IsSend=" + GetQueryString("IsSend") + "&isFrameCross=" + isFrameCross + "&PageFrom=" + GetQueryString("PageFrom"));
                else
                    SetHref(url + "&IsDelayedSend=" + isDelayedSend + "&ToNode=" + GetQueryString("ToNode") + "&IsSend=" + GetQueryString("IsSend") + "&PageFrom=" + GetQueryString("PageFrom") + "&isFrameCross=" + isFrameCross);

                return;
            }

            if (data.indexOf('BySelfUrl@') == 0) {
                var url = data.replace('BySelfUrl@', '');

                if (url.indexOf('ToNode=') > 0)
                    url += "&IsSend=" + GetQueryString("IsSend") + "&PageFrom=" + GetQueryString("PageFrom");
                else
                    url += "&ToNode=" + GetQueryString("ToNode") + "&IsSend=" + GetQueryString("IsSend") + "&isFrameCross=" + isFrameCross + "&PageFrom=" + GetQueryString("PageFrom");

                $('#returnWorkModal', parent.document).modal('hide');
                window.parent.initModal("BySelfUrl", null, url); $('#returnWorkModal', parent.document).modal().show();

                return;
            }


            //把string 转化为json.
            try {
                data = cceval('(' + data + ')');
            }
            catch (err) {
                alert("转换JSON 失败" + err + data);
                return;
            }

            //获得三个数据源.
            var depts = data.Depts; //部门集合. 这个集合也可能为空，如果为空就不要分组.
            var emps = data.Emps;  //可选的人员集合.
            var selected = data.Selected; //已经选择的人员集合.

            if (emps == null || emps == undefined || emps.length == 0) {
                alert('当前节点设置的接收人范围为空,请联系管理员配置接收人范围.');
                return;
            }

            //是否是单选？  =0 是多选   =1 是单选.
            var isSimplate = data.Selector[0].IsSimpleSelector;

            var html = "<table border=0 width='98%' style='margin: auto;margin-top:5px'>";

            if (isSimplate == "0") { //
                html += "<tr><th>&nbsp;&nbsp;<label><input  type='checkbox' name='selectAll' id='selectAll' onclick='selectAll()'  value='全选' /><b>&nbsp;全选</b></label></th></tr>";
            }

            if (depts == null) {

                $.each(emps, function (i, emp) {

                    html += "<tr><td>";
                    //检查该人员是否被选择.
                    var isSele = false;
                    $.each(selected, function (idx, sele) {
                        if (sele.No == emp.No)
                            isSele = true;
                    });

                    //多选.
                    if (isSimplate == "0") {
                        if (isSele == true)
                            html += "&nbsp;&nbsp;<label id='lab" + emp.No + "' ><input  type='checkbox' checked=true id='" + emp.No + "'  value='" + emp.Name + "' /> &nbsp;<font color=green>" + emp.Name + "</font></label>";
                        else
                            html += "&nbsp;&nbsp;<label id='lab" + emp.No + "' ><input  type='checkbox'  id='" + emp.No + "'  value='" + emp.Name + "' />&nbsp;" + emp.Name + "</label>";
                    }

                    //单选.
                    if (isSimplate == "1") {
                        if (isSele == true)
                            html += "&nbsp;&nbsp;<label id='lab" + emp.No + "'><input name='emps'  type='radio' checked=true id='" + emp.No + "' value='" + emp.Name + "' /> &nbsp;<font color=green>" + emp.Name + "</font></label>";
                        else
                            html += "&nbsp;&nbsp;<label id='lab" + emp.No + "' ><input name='emps'  type='radio'  id='" + emp.No + "'  value='" + emp.Name + "' />&nbsp;" + emp.Name + "</label>";
                    }
                });

                html += " </td></tr>";

            }

            if (depts != null) {

                $.each(depts, function (i, dept) {
                    html += "<tr><td class='TRSum' ><b> " + dept.Name + "</b></td></tr>";
                    html += "<tr><td>";

                    $.each(emps, function (i, emp) {

                        if (emp.FK_Dept == dept.No) {

                            //检查该人员是否被选择.
                            var isSele = false;
                            $.each(selected, function (idx, sele) {
                                if (sele.No == emp.No)
                                    isSele = true;
                            });

                            //多选.
                            if (isSimplate == "0") {
                                if (isSele == true)
                                    html += "&nbsp;&nbsp;<label id='lab" + emp.No + "' ><input  type='checkbox' checked=true id='" + emp.No + "'  value='" + emp.Name + "' /> <font color=green>" + emp.Name + "</font></label>";
                                else
                                    html += "&nbsp;&nbsp;<label id='lab" + emp.No + "' ><input  type='checkbox'  id='" + emp.No + "'  value='" + emp.Name + "' />" + emp.Name + "</label>";
                            }

                            //单选.
                            if (isSimplate == "1") {
                                if (isSele == true)
                                    html += "&nbsp;&nbsp;<label id='lab" + emp.No + "'><input name='emps'  type='radio' checked=true id='" + emp.No + "' value='" + emp.Name + "' /> <font color=green>" + emp.Name + "</font></label>";
                                else
                                    html += "&nbsp;&nbsp;<label id='lab" + emp.No + "' ><input name='emps'  type='radio'  id='" + emp.No + "'  value='" + emp.Name + "' />" + emp.Name + "</label>";
                            }
                        }
                    });

                    html += " </td></tr>";

                });
            }

            html += "</table>";

            $("#table").append(html);


            //只有一个人的时候.
            if (emps.length == 1) {

                //获得人员编号.
                var no = emps[0].No;
                //让其选择.
                $("#" + no).attr("checked", "checked");

                //执行发送.
                if (IsSend == 1)
                    SendNode();
            }

        });

        //保存接受人的方法.
        function SaveNodeEmps() {
            //生成选择的人员.
            var checked = $('input:checked');
            var selectedEmps = [];
            var selectedEmpLab = [];
            for (var i = 0; i < checked.length; i++) {
                if (checked[i].id == "selectAll") {
                    continue;
                }
                selectedEmps.push(checked[i].id);
                selectedEmpLab.push(checked[i].value);
            }

            selectedEmps = selectedEmps.join(',');
            selectedEmpLab = selectedEmpLab.join(',');
            if (selectedEmps == '' || selectedEmps == null) {
                alert('请选择人员.');
                return;
            }
            var handler = new HttpHandler("BP.WF.HttpHandler.WF_WorkOpt");
            handler.AddUrlData();  //WorkID,FK_Flow,FK_Node,ToNode 参数.
            handler.AddPara("SelectEmps", selectedEmps); //多个人员用逗号分开： 比如 zhangsan,lisi
            var data = handler.DoMethodReturnString("Accepter_Save"); //执行保存
            var pageFrom = GetQueryString("PageFrom");
            if (pageFrom != null && pageFrom != undefined && pageFrom == "WorkCheckModel")
                Close(false, selectedEmps);
            else
                Close(false, selectedEmpLab);  //关闭窗口.
        }

        //复选框全选反选
        function selectAll() {
            var obj = $("#selectAll");
            if (obj != null && obj != undefined && obj.prop("checked")) {
                $("input:checkbox").each(function () {
                    $(this).prop("checked", true);
                });
            } else {
                $("input:checkbox").each(function () {
                    $(this).prop("checked", false);
                });
            }
        };

        function DelayedSend() {
            var handler = new HttpHandler("BP.WF.HttpHandler.WF_MyFlow");
            handler.AddUrlData();
            var day = $("#TB_Day").val() || 0;
            var hour = $("#TB_Hour").val() || 0;
            var minute = $("#DDL_Minute").val() || 0;
            if (day == 0 && hour == 0 && minute == 0) {
                layer.alert("请设置延期发送的时间");
                return;
            }
            //生成选择的人员.
            var checked = $('input:checked');
            var selectedEmps = [];
            for (var i = 0; i < checked.length; i++) {
                if (checked[i].id == "selectAll") {
                    continue;
                }
                selectedEmps.push(checked[i].id);
            }
            selectedEmps = selectedEmps.join(';');
            if (selectedEmps == '' || selectedEmps == null) {
                layer.alert('请选择人员.');
                return;
            }

            handler.AddPara("TB_Day", day);
            handler.AddPara("TB_Hour", hour);
            handler.AddPara("DDL_Minute", minute);
            handler.AddPara("ToNodeID", GetQueryString("ToNode"));
            handler.AddPara("ToEmps",selectedEmps)
            var data = handler.DoMethodReturnString("DelayedSend");
            if (data.indexOf("err@") != -1) {
                layer.alert(data);
                return;
            }
            Close(true);
        }

        //确定【选择接收人并发送】 / 保存.  Accepter_Save Accepter_Send
        function SendNode() {
            //生成选择的人员.
            var checked = $('input:checked');
            var selectedEmps = [];
            for (var i = 0; i < checked.length; i++) {
                if (checked[i].id == "selectAll") {
                    continue;
                }
                selectedEmps.push(checked[i].id);
            }
            selectedEmps = selectedEmps.join(';');
            if (selectedEmps == '' || selectedEmps == null) {
                layer.alert('请选择人员.');
                return;
            }
            if (pageFrom != null && pageFrom != undefined && pageFrom == "WorkCheckModel") {
                window.parent.returnWorkWindowClose(selectedEmps);
                return;
            }

            $("#Msg").html("<font color=green><center>正在发送请稍候...</center></font>");

            var handler = new HttpHandler("BP.WF.HttpHandler.WF_WorkOpt");
            handler.AddUrlData(); //FK_Flow,WorkID,FK_Node,ToNode 参数.

            //多个参数用逗号分开的比如： zhangsan;lisi;wangwu
            handler.AddPara("SelectEmps", encodeURI(selectedEmps));
            var data = handler.DoMethodReturnString("Accepter_Send"); //执行发送方法.
            if (data.indexOf('err@') == 0) {
                alert(data);
                return;
            }
            if (isFrameCross == 0) {
                if (window.parent != null && window.parent.WindowCloseReloadPage != null && typeof window.parent.WindowCloseReloadPage === "function") {
                    window.parent.WindowCloseReloadPage(data);
                } else {
                    if (typeof WindowCloseReloadPage != 'undefined' && WindowCloseReloadPage instanceof Function)
                        WindowCloseReloadPage(data);
                }
            } else {
                ChildrenPostMessage(data, "WindowCloseReloadPage");
            }


            data = data.replace("'MyFlowInfo", "'../MyFlowInfo");
            data = data.replace("'MyFlow.htm", "'../MyFlow.htm");
            data = data.replace("'MyFlow.htm", "'../MyFlow.htm");

            data = data.replace("'WFRpt", "'../WFRpt");
            data = data.replace("'WFRpt", "'../WFRpt");

            data = data.replace("'./Img", "'../Img");
            data = data.replace("'./Img", "'../Img");
            data = data.replace("'./Img", "'../Img");
            data = data.replace("'./Img", "'../Img");
            data = data.replace("'./Img", "'../Img");

            if (data.indexOf("UnSend.htm") == -1) {
                data = data.replace("'./WorkOpt/", "");
                data = data.replace("'./WorkOpt/", "");
                data = data.replace("'./WorkOpt/", "");
            }

            data = data.replace('@', '<br/>@');
            data = data.replace(/@/g, '<br/>&nbsp;@');
            data = data.replace('<br/><br/>&nbsp;', '');
            //console.log(data);

            if ("Accepter_Save" == doType) {
                if (isFrameCross == 0) {
                    if (window.parent != null && window.parent.returnWorkWindowClose != null) {
                        window.parent.returnWorkWindowClose(data);
                    } else if (window.opener != undefined && window.opener.returnWorkWindowClose != undefined) {
                        window.opener.returnWorkWindowClose(data);
                    } else if (window.parent != undefined && window.parent.AccepterHtmlSave != undefined) {
                        //表单树使用
                        window.parent.AccepterHtmlSave(data);
                    } else {
                        $('body').append($('<div>' + data + '</div>'));
                        $('#btnSave').attr('disabled', true);
                    }
                } else {
                    ChildrenPostMessage(data, "returnWorkWindowClose");
                }

                try {
                    window.opener.document.getElementById("acc_link_" + ToNode).innerHTML = "选择接受人员" + "<span style='color:black;'>(" + getSaveName + ")</span>";
                } catch (e) {
                    //window.parent.document.getElementById("acc_link_" + ToNode).innerHTML = "选择接受人员" + "<span style='color:black;'>(" + getSaveName + ")</span>";
                }
                //alert('保存成功...');
                window.close();
                return;
            }

            if (isFrameCross == 0) {
                if (window.parent != null && window.parent.returnWorkWindowClose != null) {
                    window.parent.returnWorkWindowClose(data);
                } else if (window.opener != undefined && window.opener.returnWorkWindowClose != undefined) {
                    window.opener.returnWorkWindowClose(data);
                } else {
                    $('body').append($('<div>' + data + '</div>'));
                    $('#btnSave').attr('disabled', true);
                }
            } else {
                ChildrenPostMessage(data, "returnWorkWindowClose");
            }
            $(".foot").hide();
        }

        //取消【选择接收人并发送】
        function Close(flag, selectEmps) {
            if (selectEmps == null || selectEmps == undefined)
                selectEmps = "取消"
            if (isFrameCross == 0) {
                if (window.parent != null && window.parent.returnWorkWindowClose != null) {
                    window.parent.returnWorkWindowClose(selectEmps);
                    if (flag == true)
                        window.parent.close();
                    else
                        window.close();
                } else if (window.opener != undefined && window.opener.returnWorkWindowClose != undefined) {
                    window.opener.returnWorkWindowClose(selectEmps);
                    if (flag == true)
                        window.opener.close();
                    else
                        window.close();
                } else {
                    window.close();
                }
            } else {
                ChildrenPostMessage(selectEmps, "returnWorkWindowClose");
                if (flag == true)
                    window.parent.close();
                else
                    window.close();
            }

        }
        //初始化人员选择窗口
        function initSelectEmpModal() {
            var selectEmpModalHtml = '<div class="modal fade" id="selectEmpsModal" style="width: 80%;margin: 40px auto;">' +
                '<div class="modal-dialog" style="margin: 0px;width:700px;">'
                + '<div class="modal-content" style="border-radius:0px;">'
                + '<div class="modal-header">'
                + '<button type="button" class="close" style="opacity:1;" data-dismiss="modal" aria-hidden="true">&times;</button>'
                + '<h4 class="modal-title">选择人员</h4>'
                + '</div>'
                + '<div class="modal-body">'
                + '<iframe style="width:100%;border:0px;height:400px;" id="iframeSelectEmpsForm" name="iframeSelectEmpsForm"></iframe>'
                + '</div>'
                + '</div><!-- /.modal-content -->'
                + '</div><!-- /.modal-dialog -->'
                + '</div>';

            $('body').append($(selectEmpModalHtml));

            $('#BtnSelectEmps').bind('click', function () {

                var dept = getQueryStringByNameFromUrl("?" + $.cookie('CCS'), "FK_Dept");
                if (dept == null || dept == '' || dept == undefined) {
                    dept = $.cookie('FK_Dept');
                }
                if (dept == null || dept == '' || dept == undefined) {
                    var u = new WebUser();
                    dept = u.FK_Dept;
                }
                $('#iframeSelectEmpsForm').attr('src', "SelectEmps.htm?FK_Dept=" + dept + "&FK_Node=" + GetQueryString("FK_Node") + "&s=" + Math.random() + "&IsSelectMore=1");
                $('#selectEmpsModal').modal().show();
            });
        }

        //设置选中的人员
        function selectEmpsWindowClose(data) {
            $('#selectEmpsModal').modal('hide');
            if (data == '取消') {
                return;
            }

            $('#ToEmp').val(frames["iframeSelectEmpsForm"].window.returnVal.Name);
        }
    </script>
    <style type="text/css">
        .TRSum {
            font-size: 14px;
            background-color: #FFFFFF;
            border-bottom-style: double;
            border-bottom-width: 2px;
            border-bottom-color: #fafafa;
            border-right-style: none;
            border-left-style: none;
        }
    </style>
</head>
<body>
    <div style="margin-bottom:45px;">
        <div id="selected">
        </div>
        <div style="margin:10px;display:none" id="Div_DelayedSend">
            <div class="form-unit">设置延期时间</div>
            <div class="layui-form" style="margin-top:10px">
                <div class="layui-form-item">
                    <div class="layui-input-inline">
                        <input type="text" name="TB_Day" id="TB_Day" class="layui-input" value="0" />
                    </div>
                    <label class="layui-form-label">天</label>
                    <div class="layui-input-inline">
                        <input type="text" name="TB_Hour" id="TB_Hour" class="layui-input" value="0" />
                    </div>
                    <label class="layui-form-label">小时</label>
                    <div class="layui-input-inline">
                        <select name="DDL_Minute" id="DDL_Minute">
                            <option value="0">0</option>
                            <option value="15">15</option>
                            <option value="30">30</option>
                            <option value="45">45</option>
                        </select>
                    </div>
                    <label class="layui-form-label">分</label>
                </div>
            </div>
            <div class="form-unit">选择接收人</div>
        </div>
        <div id="table"></div>
    </div>
    <div style="position: fixed;background:#f5f5f5; left:0; padding:8px; text-align:right; border-top:solid 1px #ccc; bottom: 0; right: 0;" class="foot">

        <button onclick="SaveNodeEmps();"
                id="Btn_Save" style="display:none" class="layui-btn layui-btn-normal">
            <!--<img src="../Img/Btn/Confirm.png" />--> 保存
        </button>
        <button onclick="SendNode();" id="Btn_Send" class="layui-btn layui-btn-primary">
            <!--<img src="../Img/Btn/Send.png" />--> 发送
        </button>
        <button onclick="DelayedSend();" id="Btn_DelayedSend" class="layui-btn layui-btn-primary" style="display:none">
            <!--<img src="../Img/Btn/Send.png" />--> 延期发送
        </button>

        <button onclick="Close();" id="btnCancel" class="layui-btn layui-btn-primary">
            <!--<img src="../Img/Btn/Close.png" />--> 关闭
        </button>
    </div>
    <br />
    <center>
        <div id="Msg">
        </div>
    </center>
</body>
</html>
